#include "Light.h"

#include "../Math/Point.h"

using namespace Graphics;
using namespace Math;

Light::Light(GLenum light):Renderable(NULL,true), _light(light)
{
	//_position=Point(0.0f,2.0f,0.0f);
	//GLfloat spot_direction[]={0.0f,-10.0f,0.0f};
	GLfloat light_specular[]={0.8f,0.8f,0.8f,1.0f};
	GLfloat light_ambient[]={0.2f,0.2f,0.2f,1.0f};
	GLfloat light_diffuse[]={1.0f,1.0f,1.0f,1.0f};

	glLightf(_light, GL_CONSTANT_ATTENUATION, 0.8f);
	glLightfv(_light, GL_AMBIENT, light_ambient);
	glLightfv(_light, GL_DIFFUSE, light_diffuse);
	glLightfv(_light, GL_SPECULAR, light_specular);
	//glLightfv(_light, GL_SPOT_DIRECTION, spot_direction);
	//glLightf(_light, GL_SPOT_CUTOFF, 5.0);
	resetPosition();
	glEnable(light);
}

void Light::setPosition(const Point& pos)
{
	Renderable::setPosition(pos);

	resetPosition();
}

void Light::resetPosition()
{
	glPushMatrix();
	//glLoadIdentity();
	GLfloat position[]={_position.x(),_position.y(),_position.z(),1.0f};
	//GLfloat position[]={0.0f,0.3f,-0.3f,1.0f};
	glLightfv(_light,GL_POSITION,position);
	glPopMatrix();
}
